#!/bin/sh
uci get shadowsocks.@general[-1] >/dev/null 2>&1 || \
	uci add shadowsocks general >/dev/null 2>&1
uci get shadowsocks.@transparent_proxy[-1] >/dev/null 2>&1 || \
	uci add shadowsocks transparent_proxy >/dev/null 2>&1
uci get shadowsocks.@socks5_proxy[-1] >/dev/null 2>&1 || \
	uci add shadowsocks socks5_proxy >/dev/null 2>&1
uci get shadowsocks.@port_forward[-1] >/dev/null 2>&1 || \
	uci add shadowsocks port_forward >/dev/null 2>&1
uci get shadowsocks.@access_control[-1] >/dev/null 2>&1 || \
	uci add shadowsocks access_control >/dev/null 2>&1
uci commit shadowsocks
uci -q batch <<-EOF >/dev/null
	delete ucitrack.@shadowsocks[-1]
	add ucitrack shadowsocks
	set ucitrack.@shadowsocks[-1].init=shadowsocks
	commit ucitrack
	delete firewall.shadowsocks
	set firewall.shadowsocks=include
	set firewall.shadowsocks.type=script
	set firewall.shadowsocks.path=/var/etc/shadowsocks.include
	set firewall.shadowsocks.reload=1
	commit firewall
EOF
exit 0
